<?php
/* tblCustomerNotes */
class tblCustomerNotes extends NocForm
	{
		protected $_ID                 = array();
		protected $_Customer                 = array();
		protected $_Note                 = array();
		protected $_TimeStamp                 = array();
		protected $_Staff                 = array();
		protected $_UploadedDocument                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_Customer()
		{
				return  $this->_get_CustomerValue();
		}

		private function _get_CustomerValue()
		{
			if(isset($this->_Customer['value']))
				return $this->_Customer['value'];
			else
				return false;
		}

		public function get_Note()
		{
				return  $this->_get_NoteValue();
		}

		private function _get_NoteValue()
		{
			if(isset($this->_Note['value']))
				return $this->_Note['value'];
			else
				return false;
		}

		public function get_TimeStamp()
		{
				return  $this->_get_TimeStampValue();
		}

		private function _get_TimeStampValue()
		{
			if(isset($this->_TimeStamp['value']))
				return $this->_TimeStamp['value'];
			else
				return false;
		}

		public function get_Staff()
		{
				return  $this->_get_StaffValue();
		}

		private function _get_StaffValue()
		{
			if(isset($this->_Staff['value']))
				return $this->_Staff['value'];
			else
				return false;
		}

		public function get_UploadedDocument()
		{
				return  $this->_get_UploadedDocumentValue();
		}

		private function _get_UploadedDocumentValue()
		{
			if(isset($this->_UploadedDocument['value']))
				return $this->_UploadedDocument['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_CustomerValue($strCustomer)
		{
			if($this->validateInput("validatexxxxx", $strCustomer, "Customer "))
					return($this->_setNewValue($this->_Customer, $strCustomer));
			else
					return false;
		}

		public function set_NoteValue($strNote)
		{
			if($this->validateInput("validatexxxxx", $strNote, "Note "))
					return($this->_setNewValue($this->_Note, $strNote));
			else
					return false;
		}

		public function set_TimeStampValue($strTimeStamp)
		{
			if($this->validateInput("validatexxxxx", $strTimeStamp, "TimeStamp "))
					return($this->_setNewValue($this->_TimeStamp, $strTimeStamp));
			else
					return false;
		}

		public function set_StaffValue($strStaff)
		{
			if($this->validateInput("validatexxxxx", $strStaff, "Staff "))
					return($this->_setNewValue($this->_Staff, $strStaff));
			else
					return false;
		}

		public function set_UploadedDocumentValue($strUploadedDocument)
		{
			if($this->validateInput("validatexxxxx", $strUploadedDocument, "UploadedDocument "))
					return($this->_setNewValue($this->_UploadedDocument, $strUploadedDocument));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblCustomerNotes
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_Customer['updated'])
					{
						$strSql .= $strJoin." Customer = '".$this->_Customer['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Customer['oldvalue']."' to '".$this->_Customer['value']."'<br/>";
						$strErrorMsg .= "Customer not updated<br/>";					}

					if($this->_Note['updated'])
					{
						$strSql .= $strJoin." Note = '".$this->_Note['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Note['oldvalue']."' to '".$this->_Note['value']."'<br/>";
						$strErrorMsg .= "Note not updated<br/>";					}

					if($this->_TimeStamp['updated'])
					{
						$strSql .= $strJoin." TimeStamp = '".$this->_TimeStamp['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_TimeStamp['oldvalue']."' to '".$this->_TimeStamp['value']."'<br/>";
						$strErrorMsg .= "TimeStamp not updated<br/>";					}

					if($this->_Staff['updated'])
					{
						$strSql .= $strJoin." Staff = '".$this->_Staff['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_Staff['oldvalue']."' to '".$this->_Staff['value']."'<br/>";
						$strErrorMsg .= "Staff not updated<br/>";					}

					if($this->_UploadedDocument['updated'])
					{
						$strSql .= $strJoin." UploadedDocument = '".$this->_UploadedDocument['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_UploadedDocument['oldvalue']."' to '".$this->_UploadedDocument['value']."'<br/>";
						$strErrorMsg .= "UploadedDocument not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblCustomerNotes()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblCustomerNotes
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblCustomerNotes = new MySqlResults($strSql);
		
				if(!$qryDeletetblCustomerNotes->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblCustomerNotes()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblCustomerNotes
						  (
		 	Customer

		, 	Note

		, 	TimeStamp

		, 	Staff

		, 	UploadedDocument
)VALUE(
		 	$this->get_CustomerValue() 
		, 	$this->get_NoteValue() 
		, 	$this->get_TimeStampValue() 
		, 	$this->get_StaffValue() 
		, 	$this->get_UploadedDocumentValue() 
			)";
			
			$qryInserttblCustomerNotes = new MySqlResults($strSql);
		if ($qryInserttblCustomerNotes->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblCustomerNotes");
			
		return true;
	}
	}

?>